package annotation.repeatable;

import java.lang.annotation.Annotation;

public class MyRepeatableTest {

    public static void main(String[] args) {
        Class myRepeatableEntityClass = MyRepeatableEntity.class;

        // 获得当前Class(MyRepeatableEntity)所有的所有注解
        Annotation[] annotations = myRepeatableEntityClass.getAnnotations();
        System.out.println("当前类的注解数量：" + annotations.length); // 当前类的注解数量：1

        // @annotation.repeatable.MyRepeatables(value=[@annotation.repeatable.MyRepeatable(role=aaa), @annotation.repeatable.MyRepeatable(role=bbb)])
        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }

        // 判断是否有特定的Annotation
        boolean annotationPresent = myRepeatableEntityClass.isAnnotationPresent(MyRepeatables.class);
        if (annotationPresent) {
            MyRepeatables myRepeatables = (MyRepeatables) myRepeatableEntityClass.getAnnotation(MyRepeatables.class);

            MyRepeatable[] myRepeatableArr = myRepeatables.value();
            for (MyRepeatable myRepeatable : myRepeatableArr) {
                String role = myRepeatable.role();
                System.out.println(role);
                System.out.println("--------------");
            }
        }

        //aaa
        //--------------
        //bbb
        //--------------

    }

}
